import { ref } from 'vue'

export const status = ref(false);
const moveIng = ref(true);
const startX = ref(0);
const startY = ref(0);
const lastWidth = ref(0);
const lastHeight = ref(0);
function move (event:any){
  if (!moveIng.value) return;
  const x:any = window.screenX + event.clientX - startX.value
  const y:any = window.screenY + event.clientY - startY.value
  // 调用主进程函数
  // @ts-ignore
  window.api.moveBounds(parseInt(x), parseInt(y), lastWidth.value, lastHeight.value);
}
  window.addEventListener('mousedown',(event:any)=>{
    event.preventDefault();
    if(status.value){
      return;
    }
    moveIng.value = true;
    startX.value = parseInt(event.clientX);
    startY.value = parseInt(event.clientY);
    lastWidth.value = window.outerWidth;
    lastHeight.value = window.outerHeight;
    document.addEventListener('mousemove', move);
  });
  window.addEventListener('mouseup',(event:any)=>{
    event.preventDefault();
    if (!moveIng.value) return
    document.removeEventListener('mousemove', move)
    moveIng.value = false
  });
  window.addEventListener('contextmenu',()=>{
    if (!moveIng.value) return
    document.removeEventListener('mousemove', move)
    moveIng.value = false
  });

